package com.eudon.design_pattern.behavioral.state.search_table;


import com.eudon.design_pattern.behavioral.state.search_table.mario_state.Event;
import com.eudon.design_pattern.behavioral.state.search_table.mario_state.MarioState;

/**
 * @author eudon
 * @description 马里奥状态机，查表法
 * @date 2025/9/3
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class MarioStateMachine {
    private final MarioState[][] stateTable = {
            {MarioState.SUPER,MarioState.CAPE,MarioState.FIRE,MarioState.SMALL},
            {MarioState.SUPER,MarioState.CAPE,MarioState.FIRE,MarioState.SMALL},
            {MarioState.CAPE,MarioState.CAPE,MarioState.CAPE,MarioState.SMALL},
            {MarioState.FIRE,MarioState.FIRE,MarioState.FIRE,MarioState.SMALL}
    };
    private final int[][] scoreTable = {
            {100,200,300,0},
            {0,200,300,-100},
            {0,0,0,-200},
            {0,0,0,-300}
    };
    private MarioState marioState;
    private int score;
    MarioStateMachine(MarioState marioState) {
        this.marioState = marioState;
        this.score = 0;
    }

    public MarioState getMarioState() {
        return marioState;
    }
    public int getScore() {
        return score;
    }
    public void eventExecute(Event event) {
        int stateValue = marioState.getValue();
        int eventValue = event.getValue();
        marioState = stateTable[stateValue][eventValue];
        score = score + scoreTable[stateValue][eventValue];
    }
}
